<template>
	<view class="content">
		<uni-search-bar @confirm="search1" :focus="true" v-model="searchValue" @blur="blur" @focus="focus" @input="input"
						@cancel="cancel" @clear="clear" placeholder="请输入您要搜索的昵称或ID">
		</uni-search-bar>
		<view class="userlist">
			<view class="user" v-for="(item, index) in list">
				<view class="left">
					<view class="two">
						<image :src="item.avatar" mode=""></image>
					</view>
					<view class="three">{{item.user_nicename}}</view>
					<view class="imglist">
						<view class="sex">
							<image src="/static/image/my/nan.png" mode="" v-if="item.sex == 1"></image>
							<image src="/static/image/my/nv.png" mode="" v-if="item.sex == 2"></image>
						</view>
						<view class="level">
							<image :src="$api.levelanchorimg(item.level_anchor)" mode=""></image>
						</view>
						<view class="level_anchor">
							<image :src="$api.levelimg(item.level)" mode=""></image>
						</view>
					</view>
				</view>
				<view class="right" v-if="item.isattention == 0" @click="setAttent(item.id)">关注</view>
				<view class="right right2" v-if="item.isattention == 1" @click="setAttent(item.id)">已关注</view>
			</view>
			<!-- <view class="" v-if="show">
				<text>{{title}}</text>
				<text>{{des}}</text>
			</view> -->
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				searchValue:'',
				title:'',
				des:'',
				page:1,
				overList: false,
				jiazai: true,
				list: [],
			}
		},
		onReachBottom() {
			if (this.overList) {
				uni.showToast({
					title: '加载完毕'
				})
				console.log(this.overList);
			} else {
				if (!this.jiazai) {
					return false;
				}
				this.jiazai = false;
				this.page++;
				this.search();
			}
		},
		methods: {
			// 关注|取消关注
			setAttent(touid){
				var token = '';
				var uid = 0;
				if(uni.getStorageSync('token')){
					token = uni.getStorageSync('token');
					uid = uni.getStorageSync('uid');
				}
				this.$api.sendRequest({
					data:{
						service:'User.setAttent',
						uid:uid,
						token:token,
						touid:touid,
					},
					success: res => {
						if(res.data.code == 0){
							var param = res.data.info[0];
							this.search();
						}else{
							var msg = res.msg == '' ? res.data.msg : res.msg;
							uni.showToast({
								icon: "none",
								title: msg,
							});
						}
					}
				});
			},
			search(){
				var token = '';
				var uid = 0;
				if(uni.getStorageSync('token')){
					token = uni.getStorageSync('token');
					uid = uni.getStorageSync('uid');
				}
				this.$api.sendRequest({
					data:{
						service:'Home.search',
						uid:uid,
						token:token,
						key:this.searchValue,
						p:this.page,
					},
					success: res => {
						if(res.data.code == 0){
							let Arr = [];
							var param = res.data.info;
							Arr = param;
							if (Arr.length == 0) {
								this.overList = true;
							}
							if(this.page == 1){
								this.list = [];
							}
							this.list = this.list.concat(Arr);
						}
						this.jiazai = true;
					}
				});
			},
			search1(){
				if(this.searchValue != ''){
					this.page = 1;
					this.overList = false;
					this.search();
				}
			},
			blur(){
			},
			focus(){
			},
			input(){
				if(this.searchValue != ''){
					this.page = 1;
					this.overList = false;
					this.search();
				}
			},
			cancel(){
				uni.switchTab({
					url: "/pages/index/index",
				})
			},
			clear(){
			},
		}
	}
</script>

<style  lang="scss">
	page{
		background-color: #f2f2f2;
	}
	.uni-searchbar {
		background-color: #ffffff;
	    position: fixed;
	    top: 0;
	    left: 0;
	    width: 710rpx;
	    z-index: 999; /* 可选：设置z-index值，确保它在其他元素上方 */
		padding: 20rpx;
	  }
	  .userlist{
		  margin-top: 120rpx;
	  }
	.user{
		width: 710rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 20rpx;
		.left{
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 90rpx;
			view{
				margin-right: 30rpx;
			}
			.two{
				width: 90rpx;
				height: 90rpx;
				image{
					width: 100%;
					height: 100%;
					border-radius: 60rpx;
				}
			}
			.three{
				color: #1D1D1D;
				font-size: 30rpx;
			}
			.imglist{
				display: flex;
				align-items: center;
				.sex{
					width: 40rpx;
					height: 30rpx;
					image{
						width: 100%;
						height: 100%;
					}
					margin-right: 10rpx;
				}
				.level{
					width: 60rpx;
					height: 30rpx;
					image{
						width: 100%;
						height: 100%;
					}
					margin-right: 10rpx;
				}
				.level_anchor{
					width: 60rpx;
					height: 30rpx;
					image{
						width: 100%;
						height: 100%;
					}
				}
			}
		}
		.right{
			padding: 2rpx;
			border-radius: 60rpx;
			border: 2rpx solid #C089FF;
			color: #C089FF;
			font-size: 28rpx;
			width: 110rpx;
			text-align: center;
		}
		.right2{
			border: 2rpx solid #bbbbbb !important;
			color: #bbbbbb !important;
		}
	}
</style>
